package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmNewsDTO;
import com.heima.model.wemedia.dtos.WmNewsReviewDTO;
import com.heima.model.wemedia.dtos.WmNewsSaveDTO;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.wemedia.service.IWmNewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "自媒体文章管理API")
@RestController
@RequestMapping("api/v1/news")
public class WmNewsController {

    @Autowired
    private IWmNewsService wmNewsService;

    @ApiOperation(value = "分页带条件查询自媒体文章列表", notes = "分页带条件查询自媒体文章列表")
    @PostMapping("list")
    public ResponseResult findList(@RequestBody WmNewsDTO wmNewsDTO){
        return wmNewsService.findList(wmNewsDTO);
    }

    @ApiOperation(value = "保存自媒体文章", notes = "保存自媒体文章")
    @PostMapping("submit")
    public ResponseResult insertOrUpdateWmNews(@RequestBody WmNewsSaveDTO wmNewsSaveDTO){
        return wmNewsService.insertOrUpdateWmNews(wmNewsSaveDTO);
    }

    @ApiOperation(value = "根据 id 查询文章信息", notes = "根据 id 查询文章信息")
    @GetMapping("one/{id}")
    public ResponseResult queryWmNewsById(@PathVariable(value = "id")Integer id){
        return wmNewsService.queryWmNewsById(id);
    }

    @ApiOperation(value = "修改文章信息", notes = "leadnews-article 微服务处理文章发布修改文章状态")
    @PutMapping("update")
    public ResponseResult updateWmNewsById(@RequestBody WmNews wmNews){
        wmNewsService.updateById(wmNews);
        return ResponseResult.okResult();
    }

    @ApiOperation(value = "根据 id 删除文章信息", notes = "根据 id 删除文章信息")
    @GetMapping("del_news/{id}")
    public ResponseResult deleteWmNewsById(@PathVariable(value = "id") Integer id){
        return wmNewsService.deleteWmNewsById(id);
    }

    @ApiOperation(value = "根据 id 修改文章的上下架状态", notes = "根据 id 修改文章的上下架状态")
    @PostMapping("down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsSaveDTO wmNewsSaveDTO){
        return wmNewsService.downOrUp(wmNewsSaveDTO);
    }

    @ApiOperation(value = "运营管理端内容审核模块查询 API", notes = "运营管理端内容审核模块查询 API")
    @PostMapping("list_vo")
    public ResponseResult findWmNewsByStatus(@RequestBody WmNewsReviewDTO wmNewsReviewDTO){
        return wmNewsService.findWmNewsByStatus(wmNewsReviewDTO);
    }

    @ApiOperation(value = "运营管理端内容审核查询文章 API", notes = "运营管理端内容审核查询文章 API")
    @GetMapping("one_vo/{id}")
    public ResponseResult findWmNewsById(@PathVariable(value = "id") Integer id){
        return wmNewsService.findWmNewsById(id);
    }

    @ApiOperation(value = "运营管理端-内容审核模块-审核-通过", notes = "运营管理端-内容审核模块-审核-通过")
    @PostMapping("auth_pass")
    public ResponseResult reviewPassWmNews(@RequestBody WmNewsReviewDTO wmNewsReviewDTO){
        return wmNewsService.reviewWmNews(wmNewsReviewDTO);
    }

    @ApiOperation(value = "运营管理端-内容审核模块-审核-失败", notes = "运营管理端-内容审核模块-审核-失败")
    @PostMapping("auth_fail")
    public ResponseResult reviewFailWmNews(@RequestBody WmNewsReviewDTO wmNewsReviewDTO){
        return wmNewsService.reviewWmNews(wmNewsReviewDTO);
    }
}
